<?php
/**
 *  
 */

class ModMatchCrossSerV extends Model {

    protected $table = 'match_cross_server_server_v';

    // 表名
    public function tableName(){
        return $this->table;
    }

    public static function model($className=__CLASS__){
        return parent::model($className);
    }

    public function getDbConnection(){
        return Yii::app()->dbOss;
    }

    public function addmuch($params){
    	$result = $this->getDbConnection()->multiInsert($params, $this->table, FALSE);
    	return $result;
    }
    
    /**
     * 根据常规跨服id获取所关联的服务器
     * @param unknown $id
     * @return unknown
     */
    public function getServer($id){
    	$sql = "SELECT s.id,s.server_name,s.server_num,s.name,r.match_id,r.id as vid FROM server as s INNER JOIN match_cross_server_server_v as r ON r.server_id = s.id WHERE r.match_id ={$id}";
    	$result = $this->getDbConnection()->getAll($sql, $args);
    	return $result;
    }
    
    /**
     * 获取!=id的另外其他匹配跨服下的服务器
     * @param unknown $game
     * @param unknown $id
     */
    public function getOtherMatchServer($game,$id){
    	$sql = "SELECT match_id,server_id,v.id,s.server_name,s.server_num,mc.cross_server_name from match_cross_server_server_v as v INNER JOIN server as s on s.id = v.server_id ";
    	$sql .= " INNER JOIN match_cross_server_v as mc on mc.id = v.match_id WHERE mc.game = '{$game}'";
    	$result = $this->getDbConnection()->getAll($sql, $args);
    	return $result;
    }
    
    public function deleteForIds($ids){
    	$sql = "delete from {$this->table} WHERE id in ({$ids})";
    	$result = $this->getDbConnection()->execute($sql, $args);
    	return $result;
    }
    
    public function deleteForMatchIds($ids){
    	$sql = "delete from {$this->table} WHERE match_id in ({$ids})";
    	$result = $this->getDbConnection()->execute($sql, $args);
    	return $result;
    }
    
    /**
     * 根据匹配跨服id获取所配置的服务器
     * @param unknown $routine_id
     * @return unknown
     */
    public function getUseServer($match_id){
    	$sql = "SELECT * FROM {$this->table} WHERE match_id !={$match_id}";
    	$result = $this->getDbConnection()->getAll($sql, $args);
    	return $result;
    }
    
    
} 